﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoolERP_Entities;

namespace CoolERP_DAL
{
    public interface IZL_GYSDAL : IDAL<ZL_GYS>
    {
        List<ZL_GYS> GetGYS(Func<ZL_GYS, bool> exp, string orderExpr, int? pageIndex, int pageSize, out int totalCount);
    }

    public class ZL_GYSDAL : BaseDAL<ZL_GYS>, IZL_GYSDAL
    {
        public ZL_GYSDAL(IUnitOfWork context)
            : base(context)
        {
        }

        public List<ZL_GYS> GetGYS(Func<ZL_GYS, bool> exp, string orderExpr, int? pageIndex, int pageSize, out int totalCount)
        {
            IQueryable<ZL_GYS> result = dataContext.ZL_GYS.Include("Region").Include("Region1");
            if (exp != null)
                result = result.Where(exp).AsQueryable();
            totalCount = result.Count();
            if (!string.IsNullOrEmpty(orderExpr))
                result = SortingExtensions.OrderUsingSortExpression(result, orderExpr);
            if (pageIndex == null)
                return result.ToList();
            else
                return result.Skip(Convert.ToInt32(--pageIndex) * pageSize).Take(pageSize).ToList();
        }
    }
}
